<?php
namespace Todo\Controller;
use Todo\Util\Mobile;

/**
 * Class MobileController
 * 移动应用控制器基类
 * @package Todo\Controller
 */
class MobileController extends BaseController {
    protected $_model = null;

    /**
     * 初始化，完成配置加载， 用户确认，菜单加载
     */
    protected function _initialize(){

        parent::_initialize();
        
        $mobile = new Mobile();
        if(!$mobile->isMobile() && !$mobile->isTablet()){
            header('Location: /space');
        }
        $this->_loadUser(false);
        if(!$this->_user && ACTION_NAME != 'index'){
            if(IS_AJAX){
                header('HTTP/1.1 401 Unauthorized');
                $out  =  array();
                $out['error']  =  '401';
                $out['message'] = '您还没有登录，请先登录!';
                $out['url'] = 'login';
                $this->ajaxReturn($out);
            }else{
                header('Location: /mobile/index');
                die();
            }
        }
    }


    /**
     * 加载模型类，需要重写
     */
    protected function _loadModel(){
        if(!$this->_model) $this->_model = D('Todo/'.MODULE_NAME.'/'.CONTROLLER_NAME);
    }


    public function index(){
        $this->display();
    }
}